'''
Created on 2014-5-4

@author: shen
'''

#coding=unicode
# -*-coding: unicode-*- 

from read_list_from_file.read_price_list import Get_Price_List
from Classify import Classify_List
import numpy as np
import matplotlib.pyplot as plt


if __name__ == '__main__':
    get_price = Get_Price_List()
    origin_list = get_price.get_infolist()
    
    list = []
    list.append({'ASIN':origin_list[0]['ASIN'] , 'price':origin_list[0]['price']})
    
    for item in origin_list:
        index = len(list)-1
        if index ==-1:
            index = 0
        if ~(item['ASIN']==list[index]):
            list.append({'ASIN':item['ASIN'] , 'price':item['price']})
    
    for i in range(0,len(list)):
        list[i] = list[i]['price']

    c = Classify_List(list)
    new_list = c.classify()
    
    
    num = len(new_list)
    
    price = []
    price_a = []
    performance = []
    
    price.append(u'0-'+str(new_list[0]['range']))
    price_a.append(2)
    performance.append(new_list[0]['count'])
    for i in range(1,num):
        price.append(str(new_list[i-1]['range'])+u'-'+str(new_list[i]['range']))
        performance.append(new_list[i]['count'])
        price_a.append(i*10+2)
    
    
#    y_pos = np.arange(len(price))
#    plt.bar(price,performance)
#    plt.yticks(y_pos, price)
    
    
    plt.xlabel(u'price_count_range')
    plt.ylabel(u'product_count')
    plt.xticks(price_a,price)
    rect = plt.bar(price_a, performance, width=8,align="center")
    plt.show()
    